package com.example.mobile2121606110syc0331;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private RadioGroup radGupMainCarType;
    private RadioButton radBtnMainSaloon;
    private RadioButton radBtnMainMPV;
    private RadioButton radBtnMainSUV;
    private RadioGroup radGupMainRooms;
    private RadioButton radGupMainRoom1;
    private RadioButton radGupMainRoom2;
    private RadioButton radGupMainRoom3;
    private RadioButton radGupMainRoom4;
    private Button btnMainCreateLine;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGupMainCarType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("radGupMainCarType", radioButton.getText().toString());
            }
        });
        radGupMainRooms.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("radGupMainRooms", radioButton.getText().toString());
            }
        });
        btnMainCreateLine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String msg="";
                int carTypeId = radGupMainCarType.getCheckedRadioButtonId();
                if(carTypeId!=-1){
                    msg=((RadioButton)findViewById(carTypeId)).getText().toString();
                }else {
                    msg="未选车型";
                }
                int roomId = radGupMainRooms.getCheckedRadioButtonId();
                if(roomId!=-1){
                    msg+=","+((RadioButton)findViewById(roomId)).getText().toString();
                }else {
                    msg+="未选生产车间";
                }
                Log.i("Button",msg);
            }
        });
    }

    private void initView() {
        radGupMainCarType = (RadioGroup) findViewById(R.id.radGupMainCarType);
        radBtnMainSaloon = (RadioButton) findViewById(R.id.radBtnMainSaloon);
        radBtnMainMPV = (RadioButton) findViewById(R.id.radBtnMainMPV);
        radBtnMainSUV = (RadioButton) findViewById(R.id.radBtnMainSUV);
        radGupMainRooms = (RadioGroup) findViewById(R.id.radGupMainRooms);
        radGupMainRoom1 = (RadioButton) findViewById(R.id.radGupMainRoom1);
        radGupMainRoom2 = (RadioButton) findViewById(R.id.radGupMainRoom2);
        radGupMainRoom3 = (RadioButton) findViewById(R.id.radGupMainRoom3);
        radGupMainRoom4 = (RadioButton) findViewById(R.id.radGupMainRoom4);
        btnMainCreateLine = (Button) findViewById(R.id.btnMainCreateLine);
    }
}